'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:ChatSettingCtrl
 * @description
 * # ChatSettingCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('ChatSettingCtrl', function(DataService, RongYService, Util) {
        var vm = this;
        this.switchNotice = function() {
            if (vm.checked) {
                RongYService.setNotificationQuietHours().then(function(data) {
                    if (data == "success") {
                        Util.Toast("设置成功")
                        vm.checked = !vm.checked;
                    }
                })
            } else {
                RongYService.removeNotificationQuietHours().then(function(data) {
                    if (data == "success") {
                        Util.Toast("设置成功")
                        vm.checked = !vm.checked;
                    }
                })
            }

        };

        this.clearAllconversion = function() {
            if (navigator.notification) {
                navigator.notification.confirm(
                    '是否清除所有会话',
                    checkConfirm,
                    '提示', ['删除', '取消']
                )
            }
        };
        var checkConfirm = function(btn) {
            if (btn == 1) {
                RongYService.clearConversations().then(function(data) {
                    if (data.status == "success") {
                        Util.Toast("清除聊天成功")
                    } else {
                        Util.Toast(data.status)
                    }
                })
            }
        }

        var getNotificationQuietHours = function() {
            RongYService.getNotificationQuietHours().then(function(data) {
                if (data.startTime) {
                    vm.checked = false
                }else{
                	vm.checked = true
                }
            })
        }
        var init = function() {
            getNotificationQuietHours();
        }
        init();
    });
